home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
gc
/
GChblkmap.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-19
|
3KB
|
113 lines
/* begincopyright
Copyright (c) 1990 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/* Routines for maintaining a cache of maps describing heap block
* layouts for various object sizes. Allows fast pointer validity checks
* and fast location of object start locations on machines (such as SPARC)
* with slow division.
*
* Boehm, March 9, 1990 10:22:45 am PST
*/
# include "xr/GCPrivate.h"
void GC_flush_map_cache()
{
register int i;
for (i = 0; i < MAXOBJSZ + 1; i++) {
obj_map[i] = 0;
}
# ifdef PRINTSTATS
GC_printf("Flushed block map cache\n");
# endif
GC_n_maps_cached = 0;
}
# ifdef RESTRICTED_INTERIOR_POINTERS
/* Consider pointers that are offset bytes displaced from the beginning */
/* of an object to be valid. */
void GC_register_displacement(offset)
long offset;
{
if (offset > MAX_OFFSET) {
GC_abort("Bad argument to GC_register_displacement");
}
if (!valid_offsets[offset]) {
valid_offsets[offset] = TRUE;
GC_flush_map_cache();
}
}
/* Is there any valid byte offset that can be truncated to the given */
/* word offset? */
static bool valid_word_offset(word_offset)
long word_offset;
{
return(
valid_offsets[WORDS_TO_BYTES(word_offset)]
|| valid_offsets[WORDS_TO_BYTES(word_offset) + 1]
|| valid_offsets[WORDS_TO_BYTES(word_offset) + 2]
|| valid_offsets[WORDS_TO_BYTES(word_offset) + 3]
);
}
# endif
/* Try to add a heap block map for objects of size sz to the cache. */
void GC_add_cache_entry(sz)
long sz;
{
register int word_no;
register int offset;
register char * cache_entry;
if (sz > MAXOBJSZ || GC_n_maps_cached == MAP_CACHE_SZ
|| obj_map[sz] != (char *)0) {
return;
}
# ifdef INTERIOR_POINTERS
if (sz >= OBJ_INVALID) {
return;
}
# endif
# ifdef PRINTSTATS
GC_printf("Adding block map for size %d\n", sz);
# endif
cache_entry = map_cache[GC_n_maps_cached];
GC_n_maps_cached++;
for (word_no = HDR_WORDS; word_no + sz <= HBLKSIZE/BYTES_PER_WORD;
word_no += sz) {
cache_entry[word_no] = 0;
for (offset = 0; offset < sz; offset++) {
# ifdef INTERIOR_POINTERS
# ifdef RESTRICTED_INTERIOR_POINTERS
cache_entry[word_no + offset] =
(valid_word_offset(offset) ? offset : OBJ_INVALID);
# else
cache_entry[word_no + offset] = offset;
# endif
# else
cache_entry[word_no + offset] = (offset == 0 ? 0 : OBJ_INVALID);
# endif
}
}
for (; word_no < HBLKSIZE/BYTES_PER_WORD; word_no++) {
cache_entry[word_no] = OBJ_INVALID;
}
obj_map[sz] = cache_entry;
}